home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d20
/
doorskl3.arc
/
DOORSKL2.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-01-15
|
8KB
|
302 lines
/**********************************************/
/* */
/* XBBS Door Skeleton -- TC 2.0/MSC 6.0a code */
/* Copyright (c) 1990/91 by M. Kimes */
/* All Rights Reserved */
/* May be freely used for >>>FREE<<< programs */
/* as long as you don't try to save any souls */
/* (nasty habit) */
/* */
/**********************************************/
/* Always include this module (with appropriate #defines) */
/**************************************************************************
Miscellaneous notes:
#define XBBS and the program will be compiled to read ONLINE.XBS
#define DORINFO and the program will be compiled to read DORINFO?.DEF
#define both and first ONLINE.XBS will be read, then DORINFO?.DEF
#define neither and all info must come from command line
#define FINDUSER and a routine to find a given user (by name) will
be compiled in (finduser()) for XBBS' USERS.BBS
#define NOREADFILE and the file reader routine (readtext()) will NOT
be compiled
set chars to be unsigned by default
this code requires a FOSSIL for serial i/o--see function fossil()
***************************************************************************/
#include "doorskel.h" /* XBBS Door include file */
#ifdef DORINFO
void _fastcall readinfo (void) { /* Read DORINFO?.DEF */
register int x;
FILE *fp;
char s[81];
sprintf(s,"DORINFO%hu.DEF",nodenumber);
if(!((fp = fopen(s,"rt")))) {
fputs("\nCouldn't open ",stdout);
fputs(s,stdout);
exit(253);
}
if(!fgets(s,81,fp)) goto EndIt;
stripcr(s);
s[63]=0;
strcpy(system_name,s);
if(!fgets(s,81,fp)) goto EndIt;
stripcr(s);
s[35]=0;
strcpy(sysop,s);
if(!fgets(s,81,fp)) goto EndIt;
stripcr(s);
s[35]=0;
x=strlen(sysop);
if(x<35) strcat(sysop," ");
if(x<36) strncat(sysop,s,36-x);
sysop[35]=0;
if(!fgets(s,81,fp)) goto EndIt;
if(atoi(&s[3])) commport=(char)atoi(&s[3]);
if(commport)commport--;
if(!fgets(s,81,fp)) goto EndIt;
baud=(word)atol(s);
if(!fgets(s,81,fp)) goto EndIt;
if(!fgets(s,81,fp)) goto EndIt;
stripcr(s);
s[35]=0;
strcpy(username,s);
if(!fgets(s,81,fp)) goto EndIt;
stripcr(s);
s[35]=0;
x=strlen(username);
if(x<35) strcat(username," ");
if(x<36)strncat(username,s,36-x);
if(!fgets(s,81,fp)) goto EndIt;
if(!fgets(s,81,fp)) goto EndIt;
if(atoi(s)) graphics=1;
if(!fgets(s,81,fp)) goto EndIt;
seclvl=(word)atol(s);
if(!fgets(s,81,fp)) goto EndIt;
timelimit = time(NULL) + (atol(s) * 60L);
EndIt:
fclose(fp);
}
#endif
#ifdef FINDUSER
word _fastcall finduser (char *users_name,struct _user *other) {
/* Finds user named users_name in users.bbs unless user isn't there
or user is locked out. Returns user # and alters structure other
to contain user's info. Info is undefined if 0 is returned. */
FILE *fp;
int handle;
register word xx;
word tempuserno = 0;
struct stat f;
if(stat(searchpath("users.bbs"),&f)) {
printm("\r\nCan't find userfile.\r\n");
return 0;
}
printfm("\r\nSearching for %s...",users_name);
strupr(users_name);
xx=0;
if (!f.st_size) {
printm("\r\nNull-length userfile.\r\n");
return 0;
}
if ((handle = sopen(searchpath("USERS.BBS"),O_RDONLY | O_BINARY,SH_DENYNONE,S_IREAD))==-1) {
printm("\r\nError opening userfile\\rn");
return 0;
}
fp = fdopen(handle,"rb");
rewind(fp);
while (!feof(fp) && !ferror(fp)) {
xx++;
if (!(xx%50)) printm(".");
if (fread(other,sizeof(struct _user),1,fp)!=1) break;
if (!(stricmp(other->name,users_name)) && (!other->deleted)) break;
if (!(stricmp(other->handle,users_name)) && (!other->deleted)) break;
}
if (((stricmp(other->name,users_name)) &&
(stricmp(other->handle,users_name))) || (other->deleted))
goto NotFound;
if (!other->stat[0]) goto NotFound;
tempuserno = (word)(ftell(fp)/(long)sizeof(struct _user));
fclose(fp);
close(handle);
if (!tempuserno) {
NotFound:
fclose(fp);
close(handle);
printfm("\r\n%s not found.\r\n",users_name);
return 0;
}
return tempuserno;
}
#endif
#ifdef XBBS
void _fastcall readconfig (void) { /* Read CONFIG.BBS */
FILE *fp;
char s[15];
if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
else strcpy(s,"config.bbs");
if(!(fp=fopen(s,"rb"))) {
Fatal:
fputs("\nCouldn't open or read ",stdout);
fputs(s,stdout);
exit(253);
}
if (fread(&conf,sizeof(conf),1,fp)!=1) goto Fatal;
fclose(fp);
strcpy(system_name,conf.system);
strcpy(sysop,conf.sysop);
commport=conf.commport;
strcpy(logfile,conf.logfile);
sysopin=conf.sysopin;
fastANSI=conf.fastANSI;
videomethod=conf.dvideo;
}
void _fastcall getonline (void) { /* Read ONLINE.XBS */
FILE *fp;
char s[90];
char numnode[4]="";
word tlmit;
if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
if (!((fp=fopen(s,"rb")))) {
fputs("\nCouldn't open ",stdout);
fputs(s,stdout);
exit(253);
}
else {
fread(&user,sizeof(struct _user),1,fp);
fread(&userno,sizeof(userno),1,fp);
fread(&tlmit,sizeof(tlmit),1,fp);
timelimit=time(NULL) + ((long)tlmit * 60L);
fread(&timeon,sizeof(timeon),1,fp);
fread(&starter,sizeof(starter),1,fp);
fread(&baud,sizeof(baud),1,fp);
fread(&pages,sizeof(pages),1,fp);
fread(&age,sizeof(age),1,fp);
fread(&timer_off,sizeof(timer_off),1,fp);
fread(&hold_time,sizeof(hold_time),1,fp);
fread(variable,(sizeof(variable[0])*10),1,fp);
fread(&mboard,sizeof(mboard),1,fp);
fread(&fboard,sizeof(fboard),1,fp);
if (fread(event,(sizeof(struct _events)*10),1,fp)<1) {
fputs("\nCame up short!\n",stdout);
goto FatalError;
}
}
if (ferror(fp)) {
FatalError:
fputs("\nCouldn't read ",stdout);
fputs(s,stdout);
exit(253);
fclose(fp);
exit(253);
}
fclose(fp);
strcpy(username,user.name);
seclvl=user.stat[0];
width=user.width;
numlines=user.length;
graphics=user.graphics;
timelimit = time(NULL) + ((long)tlmit * 60L);
}
void _fastcall prepare (void) { /* Rewrite ONLINE.XBS */
FILE *fp;
char s[90];
char numnode[4]="";
word tlmit;
if (nodenumber!=1) sprintf(numnode,"%hu",nodenumber);
sprintf(s,"%sonline%s.xbs",conf.homepath,numnode);
if(!(fp=fopen(s,"wb"))) {
fputs("\n\04Couldn't open ",stdout);
fputs(s,stdout);
fputs(" for writing.\n",stdout);
}
else {
fwrite(&user,sizeof(struct _user),1,fp);
fwrite(&userno,sizeof(userno),1,fp);
tlmit=(word)((timelimit - time(NULL)) / 60L);
fwrite(&tlmit,sizeof(tlmit),1,fp);
fwrite(&timeon,sizeof(timeon),1,fp);
fwrite(&starter,sizeof(starter),1,fp);
fwrite(&baud,sizeof(baud),1,fp);
fwrite(&pages,sizeof(pages),1,fp);
fwrite(&age,sizeof(age),1,fp);
fwrite(&timer_off,sizeof(timer_off),1,fp);
fwrite(&hold_time,sizeof(hold_time),1,fp);
fwrite(variable,sizeof(variable[0]),10,fp);
fwrite(&mboard,sizeof(struct _mboard),1,fp);
fwrite(&fboard,sizeof(struct _fboard),1,fp);
fwrite(event,sizeof(struct _events),10,fp);
if (ferror(fp)) {
fputs("\n\04Error writing ",stdout);
fputs(s,stdout);
fputs(".\n",stdout);
}
fclose(fp);
}
}
void _fastcall saveconfig (void) { /* Rewrite CONFIG.BBS */
FILE *fp;
char s[14];
if (nodenumber!=1) sprintf(s,"config%hu.bbs",nodenumber);
else strcpy(s,"config.bbs");
if (!(fp = fopen(s,"wb"))) {
fputs("\n\04Error writing ",stdout);
fputs(s,stdout);
fputs(".\n",stdout);
}
else {
fwrite(&conf,sizeof(conf),1,fp);
fclose(fp);
}
}
#endif